package com.shunhe.storage.ui.order_receive;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.util.UIUtils;
import com.ruitu.router_module.support.view.LinearItemDecoration;
import com.shunhe.storage.R;
import com.shunhe.storage.dao.model.RepoRecord;

import java.util.ArrayList;
import java.util.List;

// 入库接单
public class ReceiveOrderIn2Fragment extends Fragment {
    private RecyclerView rcv_list;// 入库单列表

    private ReceiveInOrderAdapter adapter;
    private List<RepoRecord> recordList = new ArrayList<>();

    public ReceiveOrderIn2Fragment() {

    }

    public static ReceiveOrderIn2Fragment newInstance(String status) {
        ReceiveOrderIn2Fragment fragment = new ReceiveOrderIn2Fragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        adapter = new ReceiveInOrderAdapter(getActivity());
        for (int i = 0; i < 5; i++) {
            recordList.add(new RepoRecord());
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_receive_order_in, container, false);
        rcv_list = v.findViewById(R.id.rcv_list);

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        LinearItemDecoration divider = new LinearItemDecoration.Builder(getActivity())
                .setSpan(R.dimen.deco_10_dp)
                .setColorResource(R.color.divider_list)
                .setShowLastLine(true)
                .build();
        rcv_list.addItemDecoration(divider);
        rcv_list.setLayoutManager(manager);
        rcv_list.setAdapter(adapter);
        adapter.setDataList(recordList);

        return v;
    }

    private class ReceiveInOrderAdapter extends ListBaseAdapter<RepoRecord> {

        public ReceiveInOrderAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_receive_repo_in_record_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_receive = holder.getView(R.id.tv_receive);

            tv_receive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    UIUtils.showAlertDialog(getChildFragmentManager(), "温馨提示"
                            , "是否接收该订单?",
                            "确定", "取消",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {

                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {

                                }
                            });
                }
            });
        }
    }
}